package cn.iocoder.yudao.module.promotion.controller.admin.agent;

import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import jakarta.validation.constraints.*;
import jakarta.validation.*;
import jakarta.servlet.http.*;

import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;

import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.promotion.controller.admin.agent.vo.*;
import cn.iocoder.yudao.module.promotion.dal.dataobject.agent.AgentDO;
import cn.iocoder.yudao.module.promotion.service.agent.AgentService;
import org.springframework.web.multipart.MultipartFile;

@Tag(name = "管理后台 - 客服")
@RestController
@RequestMapping("/promotion/agent")
@Validated
public class AgentController {

    @Resource
    private AgentService agentService;

    @PutMapping("/update")
    @Operation(summary = "更新客服")
    @PreAuthorize("@ss.hasPermission('promotion:agent:update')")
    public CommonResult<Boolean> updateAgent(@Valid @RequestParam String name, MultipartFile file) throws IOException {
        agentService.updateAgent(name, file);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得客服")
    @PreAuthorize("@ss.hasPermission('promotion:agent:query')")
    public CommonResult<AgentRespVO> getAgent() {
        AgentDO agent = agentService.getAgent();
        return success(BeanUtils.toBean(agent, AgentRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得客服分页")
    @PreAuthorize("@ss.hasPermission('promotion:agent:query')")
    public CommonResult<PageResult<AgentRespVO>> getAgentPage(@Valid AgentPageReqVO pageReqVO) {
        PageResult<AgentDO> pageResult = agentService.getAgentPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, AgentRespVO.class));
    }

}